import React from 'react'
import axios from 'axios'
import {withRouter} from 'react-router-dom'
import {loadData,loadDataEnd} from '../../redux/user.redux'
import {connect} from 'react-redux'
// import {foo,sb1} from '../../moduleA'
// const foo1=require('../../moduleB')
@withRouter
@connect(
    state=>state,
    {loadData,loadDataEnd}
)
class AuthRouter extends React.Component{
    componentDidMount() {
        // module exports 导出的是值的复制 es6导出的是值的引用
        // console.log(foo1,foo)
        // setTimeout(()=>{
        //     console.log(foo,sb1,foo1)
        // },1000)
        const publicList=['/login','/register']
        const pathname=this.props.location.pathname
        if(publicList.indexOf(pathname)>-1){
            return null
        }
        
        //获取用户信息
        axios.get('/user/info').then((res)=>{
            if(res.status==200){
                if(res.data.code==0){
                    //u有登录信息
                    console.log('有登录信息')
                    this.props.loadData(res.data.data)
                    // this.props.loadDataEnd()
                }else{
                    console.log(1111)
                    this.props.history.push('/login');
                    
                }
               
            }
        })
        //是否登录
        //
    }
    render(){   
        return null
    }
    
}
export default AuthRouter